package com.service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import com.dao.IAmsBisAgtgRDao;
import com.dao.IAmsBisAlmGrDao;
import com.dao.IAmsBisAlmInfoDao;
import com.dao.IAmsBisInfoDataDao;
import com.dao.IAmsRetToolRptAlmDao;
import com.dao.IBisDataDao;
import com.dao.IBisToolGrDao;
import com.icim.service.ICIMBaseService;
import com.model.Ams_bis_agtg_r;
import com.model.Ams_bis_agtg_rId;
import com.model.Ams_bis_alm_gr;
import com.model.Ams_bis_alm_info;
import com.model.Ams_bis_alm_infoId;
import com.model.Ams_bis_info_data;
import com.model.Ams_ret_tool_rpt_alm;
import com.model.Ams_ret_tool_rpt_almId;
import com.model.Bis_data;
import com.model.Bis_tool_gr;
import com.rtnBean.NotFoundRtnBeen;
import com.rtnBean.SimpleRtnBeen;
import com.tx.Amsmain.AmsmainI;
import com.tx.Amsmain.AmsmainO;
import com.tx.Amssender.AmssenderI;
import com.tx.Amssender.AmssenderO;
import com.util.GUIDGenerator;
import com.util.MqOpe;
import com.util.Util;
import static com.def.GenericDef.*;
import org.springframework.context.annotation.Scope;

@Scope("prototype")
@Service("AmsmainService")
public class AmsmainService extends ICIMBaseService{
	private static Logger logger = Logger.getLogger(AmsmainService.class);
	private static String TX_NAME = T_AMSMAIN;

	private AmsmainI inTrx;
	private AmsmainO outTrx;
	private MqOpe mqOpe;

	private String gszMsgBuf = "";
	private Timestamp gEvtTimestamp;

	@Autowired
	private IAmsRetToolRptAlmDao amsRetToolRptAlmDao;
	@Autowired
	private IAmsBisAgtgRDao amsBisAgtgRDao;
	@Autowired
	private IAmsBisAlmGrDao amsBisAlmGrDao;
	@Autowired
	private IAmsBisAlmInfoDao amsBisAlmInfoDao;
	@Autowired
	private IAmsBisInfoDataDao amsBisInfoDataDao;
	@Autowired
	private IBisDataDao bisDataDao;
	@Autowired
	private IBisToolGrDao bisToolGrDao;

	@Autowired
	private SendMsgService sendMsgService;

	public String subMainProc(String strInMsg) {
		long rtnCode = _NORMAL;
		String outMsg = null;
		gszMsgBuf = "";
		gEvtTimestamp = Util.getCurrentTimestamp();
		inTrx = new AmsmainI();
		outTrx = new AmsmainO();
		outTrx.setTrx_id(TX_NAME);
		outTrx.setType_id(TRX_OUT);
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		mqOpe = new MqOpe();

		try {
			inTrx = (AmsmainI) mqOpe.inStr2Obj(strInMsg, inTrx);
			logger.info("InTrx is " + strInMsg);

			rtnCode = subMainProc2(inTrx.getAction_flg().toCharArray()[0]);
			if (rtnCode != _NORMAL) {
				TransactionAspectSupport.currentTransactionStatus()
						.setRollbackOnly();
				outTrx.setRtn_code(String.valueOf(rtnCode));
				outTrx.setRtn_mesg(gszMsgBuf);
			} else {
				outTrx.setRtn_code(String.valueOf(RETURN_CODE_OK));
				outTrx.setRtn_mesg(RETURN_MESG_OK);
				amsBisInfoDataDao.flushCurSession();
			}
		} catch (Exception ex) {
			TransactionAspectSupport.currentTransactionStatus()
					.setRollbackOnly();
			outTrx.setRtn_mesg(ex.toString());
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			logger.error(Util.stackTraceToString(ex));
		} finally {
			outMsg = mqOpe.obj2Str(outTrx);
			return outMsg;
		}
	}

	private long subMainProc2(char actionType) {
		long lRc = _NORMAL;

		switch (actionType) {
		case 'R': {
			lRc = reportAlarm();
			break;
		}
		default: {
			gszMsgBuf = "Invalide type input: [" + actionType + "]";
			return E_AMSSENDER_INVALID_INPUT;
		}
		}

		return lRc;
	}

	/**
	 * Report a alarm
	 * 
	 * @return
	 */
	private long reportAlarm() {
		long lRc = _NORMAL;
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		Ams_ret_tool_rpt_alm ams_ret_tool_rpt_alm = new Ams_ret_tool_rpt_alm();
		Ams_bis_alm_gr ams_bis_alm_gr = new Ams_bis_alm_gr();
		Ams_bis_agtg_r ams_bis_agtg_r = new Ams_bis_agtg_r();
		Ams_bis_alm_info ams_bis_alm_info = new Ams_bis_alm_info();

		lRc = inputCheck();
		if (_NORMAL != lRc) {
			return lRc;
		}

		// Save alarm report
		rtnBeen = saveRecord(inTrx.getTool_id(), inTrx.getAlm_id());
		if (rtnBeen.getlRc() != _NORMAL) {
			return rtnBeen.getlRc();
		} else {
			ams_ret_tool_rpt_alm = (Ams_ret_tool_rpt_alm) rtnBeen.getObj();
		}

		// Find alarm group
		rtnBeen = findAlmGroup(inTrx.getAlm_id());
		if (rtnBeen.getlRc() != _NORMAL) {
			return rtnBeen.getlRc();
		} else {
			ams_bis_alm_gr = (Ams_bis_alm_gr) rtnBeen.getObj();
		}

		// Find tool group & alarm group's bind
		rtnBeen = findAlmToolGroup(ams_ret_tool_rpt_alm, ams_bis_alm_gr);
		if (rtnBeen.getlRc() != _NORMAL) {
			return rtnBeen.getlRc();
		} else {
			ams_bis_agtg_r = (Ams_bis_agtg_r) rtnBeen.getObj();
		}

		// Find alarm info setting
		rtnBeen = findAlarmInfo(ams_bis_agtg_r, ams_bis_alm_gr);
		if (rtnBeen.getlRc() != _NORMAL) {
			return rtnBeen.getlRc();
		} else {
			ams_bis_alm_info = (Ams_bis_alm_info) rtnBeen.getObj();
		}

		rtnBeen = sendAlarmAction(ams_bis_agtg_r, ams_bis_alm_info);
		if (rtnBeen.getlRc() != _NORMAL) {
			return rtnBeen.getlRc();
		}

		return _NORMAL;
	}

	/**
	 * 
	 * @param ams_bis_agtg_r
	 * @param ams_bis_alm_info
	 * @return SimpleRtnBeen
	 */
	private SimpleRtnBeen sendAlarmAction(Ams_bis_agtg_r ams_bis_agtg_r,
			Ams_bis_alm_info ams_bis_alm_info) {
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		String almType = ams_bis_agtg_r.getAlm_typ();
		String almTypeMail = almType.substring(0, 1);
		String almTypePhone = almType.substring(1, 2);
		String almTypeSMS = almType.substring(2, 3);

		// Mail
		if (_YES.equals(almTypeMail)) {
			rtnBeen = sendAlarmMail(ams_bis_agtg_r.getId().getAlmg_id(),
					ams_bis_alm_info);
			if (rtnBeen.getlRc() != _NORMAL) {
				return rtnBeen;
			}
		}

		// Phone
		if (_YES.equals(almTypePhone)) {
			rtnBeen = sendAlarmPhone(ams_bis_agtg_r.getId().getAlmg_id(),
					ams_bis_alm_info);
			if (rtnBeen.getlRc() != _NORMAL) {
				return rtnBeen;
			}
		}

		// SMS
		if (_YES.equals(almTypeSMS)) {
			rtnBeen = sendAlarmSMS(ams_bis_agtg_r.getId().getAlmg_id(),
					ams_bis_alm_info);
			if (rtnBeen.getlRc() != _NORMAL) {
				return rtnBeen;
			}
		}

		return new SimpleRtnBeen(_NORMAL);
	}

	/**
	 * 
	 * @param almg_id
	 *            Alarm group ID
	 * @param ams_bis_alm_info
	 *            Alarm info setting
	 * @return
	 */
	private SimpleRtnBeen sendAlarmSMS(String almg_id,
			Ams_bis_alm_info ams_bis_alm_info) {
		List<Ams_bis_info_data> ams_bis_info_dataList = new ArrayList<Ams_bis_info_data>();
		ams_bis_info_dataList = amsBisInfoDataDao.getAlmInfoDataList(
				ams_bis_alm_info.getId().getToolg_id(), almg_id, ALARM_SMS);
		if (null == ams_bis_info_dataList || ams_bis_info_dataList.isEmpty()) {
			gszMsgBuf = "Alarm SMS group [" + almg_id + "], alarm id["
					+ ams_bis_alm_info.getId().getAlm_id_fk()
					+ "] is active, but not set receiver";
			return new SimpleRtnBeen(E_AMSSENDER_ALM_NO_SMS_RECIVER);
		}

		String alarmLvl = ams_bis_alm_info.getAlm_lvl();
		String alarmSMSNote = ams_bis_alm_info.getAlm_sms_note();
		for (Ams_bis_info_data ams_bis_info_data : ams_bis_info_dataList) {
			logger.warn("Send alarm SMS to ["
					+ ams_bis_info_data.getId().getInfo_data() + "] :level["
					+ alarmLvl + "],[" + alarmSMSNote + "]");
		}

		return new SimpleRtnBeen(_NORMAL);
	}

	/**
	 * Call alarm phone
	 * 
	 * @param almg_id
	 *            Alarm group ID
	 * @param ams_bis_alm_info
	 *            Alarm info setting
	 * @return SimpleRtnBeen {_NORMAL || E_AMSMAIN_ALM_NO_PHONE_RECIVER}
	 */
	private SimpleRtnBeen sendAlarmPhone(String almg_id,
			Ams_bis_alm_info ams_bis_alm_info) {
		List<Ams_bis_info_data> ams_bis_info_dataList = new ArrayList<Ams_bis_info_data>();
		ams_bis_info_dataList = amsBisInfoDataDao.getAlmInfoDataList(
				ams_bis_alm_info.getId().getToolg_id(), almg_id, ALARM_PHONE);
		if (null == ams_bis_info_dataList || ams_bis_info_dataList.isEmpty()) {
			gszMsgBuf = "Alarm phone group [" + almg_id + "], alarm id["
					+ ams_bis_alm_info.getId().getAlm_id_fk()
					+ "] is active, but not set receiver";
			return new SimpleRtnBeen(E_AMSSENDER_ALM_NO_PHONE_RECIVER);
		}

		String alarmLvl = ams_bis_alm_info.getAlm_lvl();
		String alarmPhoneNote = ams_bis_alm_info.getAlm_phs_note();
		for (Ams_bis_info_data ams_bis_info_data : ams_bis_info_dataList) {
			logger.warn("Call alarm phone to ["
					+ ams_bis_info_data.getId().getInfo_data() + "] :level["
					+ alarmLvl + "],[" + alarmPhoneNote + "]");
		}

		return new SimpleRtnBeen(_NORMAL);
	}

	/**
	 * Send alarm mail
	 * 
	 * @param almg_id
	 *            Alarm group ID
	 * @param ams_bis_alm_info
	 *            Alarm info setting
	 * @return SimpleRtnBeen {_NORMAL || E_AMSMAIN_ALM_NO_MAIL_RECIVER}
	 */
	private SimpleRtnBeen sendAlarmMail(String almg_id,
			Ams_bis_alm_info ams_bis_alm_info) {
		List<Ams_bis_info_data> ams_bis_info_dataList = new ArrayList<Ams_bis_info_data>();

		ams_bis_info_dataList = amsBisInfoDataDao.getAlmInfoDataList(
				ams_bis_alm_info.getId().getToolg_id(), almg_id, ALARM_MAIL);
		if (null == ams_bis_info_dataList || ams_bis_info_dataList.isEmpty()) {
			gszMsgBuf = "Alarm mail group [" + almg_id + "], alarm id["
					+ ams_bis_alm_info.getId().getAlm_id_fk()
					+ "] is active, but not set receiver";
			return new SimpleRtnBeen(E_AMSSENDER_ALM_NO_MAIL_RECIVER);
		}

		String alarmMailHead = ams_bis_alm_info.getAlm_mail_head();
		String alarmMailNote = ams_bis_alm_info.getAlm_mail_note();
		if (null != inTrx.getNoteParam()) {
			alarmMailNote = formatAlarmNote(alarmMailNote, inTrx.getNoteParam());
		}
		
		String mailToAdds = almAddlistToString(ams_bis_info_dataList);
		SimpleRtnBeen sendAlmLrc = new SimpleRtnBeen();
		sendAlmLrc = callAlarmSender(ALARM_MAIL, alarmMailHead, alarmMailNote,
				mailToAdds, null);
		if(_NORMAL != sendAlmLrc.getlRc()){
			return sendAlmLrc; 
		}

		return new SimpleRtnBeen(_NORMAL);
	}

	/**
	 * Format alarm note info
	 * 
	 * @param alarmNote
	 *            原始报警信息，以*作为占位符
	 * @param noteParam
	 *            输入参数
	 * @return String 格式化之后的报警信息
	 */
	private String formatAlarmNote(String alarmNote, String[] noteParam) {
		String result = "";
		String[] noteAry = alarmNote.split("\\*");
		for (int i = 0, noteAryLen = noteAry.length, noteParamLen = noteParam.length; i < noteAryLen; i++) {
			result += noteAry[i];
			if (i < noteParamLen) {
				result += noteParam[i];
			}
		}
		return result;
	}

	/**
	 * Find alarm info setting
	 * 
	 * @param ams_bis_agtg_r
	 * @param ams_bis_alm_gr
	 * @return SimpleRtnBeen{ams_bis_alm_info}
	 */
	private SimpleRtnBeen findAlarmInfo(Ams_bis_agtg_r ams_bis_agtg_r,
			Ams_bis_alm_gr ams_bis_alm_gr) {
		Ams_bis_alm_info ams_bis_alm_info = new Ams_bis_alm_info();
		Ams_bis_alm_infoId ams_bis_alm_infoId = new Ams_bis_alm_infoId();

		ams_bis_alm_infoId.setAlm_id_fk(ams_bis_alm_gr.getId().getAlm_id_fk());
		ams_bis_alm_infoId.setToolg_id(ams_bis_agtg_r.getId().getToolg_id());
		ams_bis_alm_info = amsBisAlmInfoDao.get(ams_bis_alm_infoId);
		if (null == ams_bis_alm_info) {
			gszMsgBuf = new NotFoundRtnBeen(ams_bis_alm_infoId.toString(),
					Ams_bis_alm_info.class).toString();
			return new SimpleRtnBeen(E_AMS_BIS_ALM_INFO + E_READ_NOT_FOUND);
		}

		return new SimpleRtnBeen(ams_bis_alm_info);
	}

	/**
	 * Find tool group & alarm group's bind
	 * 
	 * @param ams_ret_tool_rpt_alm
	 * @param ams_bis_alm_gr
	 * @return SimpleRtnBeen{Ams_bis_agtg_r}
	 */
	private SimpleRtnBeen findAlmToolGroup(
			Ams_ret_tool_rpt_alm ams_ret_tool_rpt_alm,
			Ams_bis_alm_gr ams_bis_alm_gr) {
		Ams_bis_agtg_r ams_bis_agtg_r = new Ams_bis_agtg_r();
		Ams_bis_agtg_rId ams_bis_agtg_rId = new Ams_bis_agtg_rId();
		Bis_tool_gr bis_tool_gr = new Bis_tool_gr();
		Bis_data bis_data_TOLG = new Bis_data();

		// Get tool group
		String sqlGetToolGrp = "FROM Bis_tool_gr WHERE id.tool_id_fk='"
				+ ams_ret_tool_rpt_alm.getId().getTool_id_fk() + "'";
		bis_tool_gr = (Bis_tool_gr) bisToolGrDao.comTblRead(sqlGetToolGrp);
		if (null == bis_tool_gr) {
			gszMsgBuf = new NotFoundRtnBeen(ams_ret_tool_rpt_alm.getId()
					.getTool_id_fk(), Bis_tool_gr.class).toString();
			return new SimpleRtnBeen(E_BIS_TOOL_GR + E_READ_NOT_FOUND);
		}

		// Check tool group setting in DATA[TOLG]
		String sqlFindAMAG = "FROM Bis_data WHERE data_cate='TOLG' AND data_item='"
				+ bis_tool_gr.getId().getToolg_id() + "' ";
		bis_data_TOLG = (Bis_data) bisDataDao.comTblRead(sqlFindAMAG);
		if (null == bis_data_TOLG) {
			gszMsgBuf = new NotFoundRtnBeen("data_cate[TOLG], data_item["
					+ bis_tool_gr.getId().getToolg_id() + "]".toUpperCase(),
					Bis_data.class).toString();
			return new SimpleRtnBeen(E_BIS_DATA + E_READ_NOT_FOUND);
		}

		// Get tool group & alarm group relationship
		ams_bis_agtg_rId.setAlmg_id(ams_bis_alm_gr.getId().getAlmg_id());
		ams_bis_agtg_rId.setToolg_id(bis_tool_gr.getId().getToolg_id());
		ams_bis_agtg_r = amsBisAgtgRDao.get(ams_bis_agtg_rId);
		if (null == ams_bis_agtg_r) {
			gszMsgBuf = new NotFoundRtnBeen(ams_bis_agtg_rId.toString(),
					Bis_data.class).toString();
			return new SimpleRtnBeen(E_AMS_BIS_AGTG_R + E_READ_NOT_FOUND);
		}

		return new SimpleRtnBeen(ams_bis_agtg_r);
	}

	/**
	 * Find alarm group
	 * 
	 * @return SimpleRtnBeen{Ams_bis_alm_gr}
	 */
	private SimpleRtnBeen findAlmGroup(String alm_id) {
		Ams_bis_alm_gr ams_bis_alm_gr = new Ams_bis_alm_gr();
		Bis_data bis_data_AMAG = new Bis_data();

		String sqlFindAlarmGroup = "FROM Ams_bis_alm_gr WHERE id.alm_id_fk='"
				+ alm_id + "' ";
		ams_bis_alm_gr = (Ams_bis_alm_gr) amsBisAlmGrDao
				.comTblRead(sqlFindAlarmGroup);
		if (null == ams_bis_alm_gr) {
			gszMsgBuf = new NotFoundRtnBeen(alm_id, Ams_bis_alm_gr.class)
					.toString();
			return new SimpleRtnBeen(E_AMS_BIS_ALM_GR + E_READ_NOT_FOUND);
		}

		// Check alarm group setting in DATA[AMAG]
		String sqlFindAMAG = "FROM Bis_data WHERE data_cate='AMAG' AND data_id='"
				+ ams_bis_alm_gr.getId().getAlmg_id() + "' ";
		bis_data_AMAG = (Bis_data) bisDataDao.comTblRead(sqlFindAMAG);
		if (null == bis_data_AMAG) {
			gszMsgBuf = new NotFoundRtnBeen("data_cate[AMAG], data_item["
					+ ams_bis_alm_gr.getId().getAlmg_id() + "]", Bis_data.class)
					.toString();
			return new SimpleRtnBeen(E_BIS_DATA + E_READ_NOT_FOUND);
		}

		if (!_YES.equals(ams_bis_alm_gr.getValid_flg())) {
			gszMsgBuf = "Alarm group[" + ams_bis_alm_gr.getId().getAlmg_id()
					+ "][" + ams_bis_alm_gr.getId().getAlm_id_fk()
					+ "] not active!";
			return new SimpleRtnBeen(E_AMSSENDER_ALM_GROUP_NOT_ACTIVE);
		}

		return new SimpleRtnBeen(ams_bis_alm_gr);
	}

	/**
	 * Save alarm report
	 * 
	 * @return SimpleRtnBeen{Ams_ret_tool_rpt_alm}
	 */
	private SimpleRtnBeen saveRecord(String tool_id, String alm_id) {
		Ams_ret_tool_rpt_alm ams_ret_tool_rpt_alm = new Ams_ret_tool_rpt_alm();
		Ams_ret_tool_rpt_almId ams_ret_tool_rpt_almId = new Ams_ret_tool_rpt_almId();
		ams_ret_tool_rpt_almId.setAlm_id(alm_id);
		ams_ret_tool_rpt_almId.setTool_id_fk(tool_id);
		ams_ret_tool_rpt_alm = amsRetToolRptAlmDao.get(ams_ret_tool_rpt_almId);
		if (null == ams_ret_tool_rpt_alm) {
			Ams_ret_tool_rpt_alm ams_ret_tool_rpt_alm_new = new Ams_ret_tool_rpt_alm();
			ams_ret_tool_rpt_alm_new.setId(ams_ret_tool_rpt_almId);
			ams_ret_tool_rpt_alm_new.setEvt_timestamp(gEvtTimestamp);
			ams_ret_tool_rpt_alm_new.setUnq_seq_id(GUIDGenerator.javaGUID());
			amsRetToolRptAlmDao.save(ams_ret_tool_rpt_alm_new);
			return new SimpleRtnBeen(ams_ret_tool_rpt_alm_new);
		}

		return new SimpleRtnBeen(ams_ret_tool_rpt_alm);
	}

	/**
	 * Check input msg's items
	 * 
	 * @return
	 */
	private long inputCheck() {
		if (Util.isSpaceCheck(inTrx.getTool_id())) {
			gszMsgBuf = "Tool id is null!";
			return E_AMSSENDER_TOOL_ID_IS_NULL;
		}

		if (Util.isSpaceCheck(inTrx.getAlm_id())) {
			gszMsgBuf = "Alarm id is null!";
			return E_AMSSENDER_ALM_ID_IS_NULL;
		}

		return _NORMAL;
	}

	/**
	 * Call alarm sender service
	 * 
	 * @return SimpleRtnBeen{error_code, errot_msg}
	 */
	private SimpleRtnBeen callAlarmSender(String actionaFlg,
			String mailSubject, String mailText, String mailToAdds,
			String mailCcAdds) {
		String strInAlmMsg = "";
		String strOutAlmMsg = "";
		AmssenderI inAlmTrx = new AmssenderI();
		AmssenderO outAlmTrx = new AmssenderO();

		inAlmTrx.setTrx_id("AMSSENDER");
		inAlmTrx.setType_id("I");
		inAlmTrx.setAction_flg(actionaFlg);
		if (ALARM_MAIL.equals(actionaFlg)) {
			inAlmTrx.setMail_subject(mailSubject);
			inAlmTrx.setMail_text(mailText);
			if (!Util.isSpaceCheck(mailToAdds)) {
				inAlmTrx.setMail_toAdds(mailToAdds);
			} else {
				return new SimpleRtnBeen(E_AMSSENDER_ALM_MAIL_RECIVER_NULL,
						"Alarm mail receiver is null!");
			}
			if (!Util.isSpaceCheck(mailCcAdds)) {
				inAlmTrx.setMail_ccAdds(mailToAdds);
			}
		} else if (ALARM_SMS.equals(actionaFlg)) {
			logger.warn("短信alarm还未启用！");
		} else {
			return new SimpleRtnBeen(E_AMSSENDER_ALM_SEND_TYPE_INVALIED,
					"Alarm type [" + actionaFlg + "] is invalied!");
		}

		strInAlmMsg = mqOpe.obj2Str(inAlmTrx);
		strOutAlmMsg = sendMsgService.sendWithRepaly(strInAlmMsg);
		outAlmTrx = (AmssenderO) mqOpe.inStr2Obj(strOutAlmMsg, outAlmTrx);
		if (RETURN_CODE_OK.equals(outAlmTrx.getRtn_code())) {
			return new SimpleRtnBeen(_NORMAL);
		} else {
			return new SimpleRtnBeen(Long.valueOf(outAlmTrx.getRtn_code()),
					"Send alarm faled: [" + outAlmTrx.getRtn_mesg() + "].");
		}
	}
	
	/**
	 * 将收件人地址转化为字符串
	 * @param list
	 * @return
	 */
	private  String almAddlistToString(List<Ams_bis_info_data> list) {
		StringBuilder sb = new StringBuilder();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				if (i < list.size() - 1) {
					sb.append(list.get(i).getId().getInfo_data() + ",");
				} else {
					sb.append(list.get(i).getId().getInfo_data());
				}
			}
		}
		return sb.toString();
	}
}
